<template>
	<view class="mutual">
		<view class="short-tabs" :class="$isPC ? 'IsPC':''">
			<scroll-view scroll-x="true" class="scrollView" :scroll-into-view="tabScrollInto">
				<view class="short-tab" v-for="(item,index) in shortTabs"
				:key="index" :class="active===item.id?'active':''"
				:id="'item_'+item.id" @click="handleTab(item.id)">
					<view class="short-tab-item">
						<image :src=" item.img" mode=""></image>
						<text>{{item.cate_name}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="tab-content">
			<block v-for="(item,index) in data" :key="index">
				<block-pushs-item :item="item"></block-pushs-item>
			</block>
			<block-loading :status="status" :len="data.length"></block-loading>
		</view>
		<view :class="$isPC ? 'IsPC':''" class="count-down" v-if="type==='browse_task'">
			<text v-if="num>0">完成任务 {{num}}s 拿奖励</text>
			<text v-else>任务完成 奖励已到账</text>
		</view>
	</view>
</template>

<script>
	import BlockPushsItem from "@/components/BlockPushsItem/BlockPushsItem.vue"
	import scrollMixins from "./minxins/scrollMixins.js"
	import {completeTask} from "@/api/activity.js"
	export default {
		name: "mutual",
		mixins:[scrollMixins],
		components: {
			BlockPushsItem
		},
		data(){
			return{
				type:'',
				num:30,
				clear:null
			}
		},
		onShow(){
			//验证不等于设置的值 判定为从别的页面返回
			if(this.num !== 30){
				this.timing()
			}
		},
		onHide(){
			//隐藏页面 销毁定时器
			clearInterval(this.clear)
		},
		onUnload(){
			clearInterval(this.clear)
		},
		deactivated() {
			clearInterval(this.clear)
		},
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url:"/pages/mutual/release/release"
			})
		},
		onLoad(option) {
			//首次进来有值 
			if(option && option.type){
				if(option.type === 'browse_task'){
					this.timing()
					this.type = option.type;
				}
			}else{
				this.num = 30;
				clearInterval(this.clear)
			}
		},
		methods:{
			timing(){
				//1 浏览悬赏
				this.clear = setInterval(async ()=>{
					this.num = this.num-1;
					if(this.num === 0){
						clearInterval(this.clear)
						await completeTask({keyword:"browse_task"})
					}
				},1000)
			}
		}
	}
</script>

<style scoped lang="less" src="./mutual.less"></style>
